package com.demo.servlet.demo1210;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet("/demo1210/demo04.do")
public class Demo04Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        //1.使用 request 对象的域对象特性
        req.setAttribute("demo04", "Demo04Servlet 在该请求对象中加入了该键值对");
        req.setAttribute("demo", "demo04");
        PrintWriter writer = resp.getWriter();
        writer.print("Demo04Servlet 正在打印<br/>");
        writer.print("attributeName = " + "demo" + ", attributeValue = " + req.getAttribute("demo") + "<br/>");
        writer.print("attributeName = " + "demo02" + ", attributeValue = " + req.getAttribute("demo02") + "<br/>");
        writer.print("attributeName = " + "demo03" + ", attributeValue = " + req.getAttribute("demo03") + "<br/>");
        writer.print("attributeName = " + "demo04" + ", attributeValue = " + req.getAttribute("demo04") + "<br/>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
